#!/bin/bash
dir=$(dirname $0)
cd ${dir}

# 下面的内容根据实际情况修改
MODULE=app
PORT=8005
export JAVA_HOME=/home/sdx/tools/jdk-11.0.2 # 物理机部署时需要指定该路径

task_status=$(ps -ef | grep ${MODULE} | grep -v grep | wc -l)
if [[ task_status -eq 0 ]];then
  nohup java -jar ${MODULE}-0.0.1-SNAPSHOT.jar \
        --server.port=8041 > /dev/null 2>&1 &
  echo "starting...please wait..."
  sleep 5
else
  echo "task is running...no need to start..."
fi
#增加 pid 信息输出，pid 以及运行时长
PID=$(ps -ef | grep ${MODULE} |grep -v grep |awk '{print $2}')
runtime=$(ps -o etimes= -p ${PID})
echo "PID:${PID},total RUNTIME:${runtime} seconds"

echo $(date) "success"